<?php

/**
 * MVM_MALL 网上商店系统  会员注册
 * ============================================================================
 * 版权所有 (C) 2007-2010 www.mvmmall.com，并保留所有权利。
 * 网站地址: http://www.mvmmall.com
 * ----------------------------------------------------------------------------
 * 这是一个免费开源的软件；这意味着您可以在不用于商业目的的前提下对程序代码
 * 进行修改、使用和再发布。
 * ============================================================================
 * $Author:  www.mvmmall.com  $
 * $Date: 2008-02-03 $
 * $Id: register.php  www.mvmmall.com$
 * ---------------------------------------------
*/
define('MVMMALL_SCR','register');
require_once './include/common.inc.php';
//判断是否开通注册
$mm_member_reg=='0' && show_msg('reg_close');
$m_check_id         &&  move_page('./');

if ($ps_mode == 'write'){
	//登陆验证码判断
	if($mm_reg_code==1){
		require_once MVMMALL_ROOT.'./include/captcha.class.php';
		$Captcha = new  Captcha();
		$code    = trim($code);
		!$Captcha->CheckCode($code) &&	show_msg('code_wrong');
	}
	is_null($login_id) && show_msg('intput_member');
	(strlen($login_id)<4  || strlen($login_id)>15) && show_msg('member_check');
	!$pass1    && show_msg('password_require');
	$pass1 != $pass2 && show_msg('password_rqual');
	$login_id  = dhtmlchars($login_id);
	$email     = dhtmlchars($email);
	$birthday  = $birth_yy.sprintf("%02d",$birth_mm).sprintf("%02d",$birth_dd);
	$pass1     = md5($pass1);
	if(!ereg("^[-a-zA-Z0-9_\.]+\@([0-9A-Za-z][0-9A-Za-z-]+\.)+[A-Za-z]{2,5}$",$email)){
		show_msg('email_err');
	}
	foreach($char_key as $value){
		strpos($login_id,$value)!==false && show_msg('user_err');
	}
	$rt_user = $db->get_one("SELECT member_id FROM `{$tablepre}member_table` WHERE member_id = '$login_id'");
	$rt_user['member_id'] && show_msg('user_mudb');
	$rt_email = $db->get_one("SELECT member_email FROM `{$tablepre}member_table` WHERE member_email = '$email'");
	$rt_email['member_email'] && show_msg('user_email');

	// 推广modify_id相当于注册人，point_id相当于推荐人，point_category属性, point_add奖励数量
	if ($mm_extend == '1' && $_COOKIE['userid'] && $mm_monynums > 0){
		$userid   = dhtmlchars($_COOKIE['userid']);
		setcookie("userid", "", time()-86400);
		$new_point_text    = "$lang[best_user] $userid";
		$query       = "INSERT INTO `{$tablepre}point_table` SET
                      point_id       = '$userid',
                      point_add      = '$mm_monynums',
                      point_reason   = '$new_point_text',
                      modify_id      = '$login_id',
                      point_category = '6',
                      modify_ip      = '$m_user_ip',
                      register_date  = '$m_now_time'";
		$db->query($query);
	}
	else {
		$userid='0';
	}
	// end
	$rows = array(
	'member_class'        => $mm_grade,
	'member_id'           => $login_id,
	'member_pass'         => $pass1,
	'member_name'         => $name,
	'member_jumin'        => $jumin,
	'member_sex'           => $sex,
	'member_birthday'     => $birthday,
	'member_tel1'         => $tel1,
	'member_tel2'         => $tel2,
	'member_email'        => $email,
	'member_automail'     => $automail,
	'member_zip'          => $zip1,
	'province'            => $province,
	'city'                => $city,
	'member_address'      => $address1,
	'member_homepage'     => $homepage,
	'icq'                 => $icq,
	'qq'                  => $qq,
	'yahoo'               => $yahoo,
	'msn'                 => $msn,
	'taobao'              => $taobao,
	'member_automail'     => $automail,
	'member_recommend'    => $userid,
	'member_introduction' => $intro,
	'member_point'        => $mm_point_member,
	'member_money'        => $mm_mony_member,
	'member_image'        => $member_file_text,
	'member_login'        => 0,
	'modify_ip'           => $m_user_ip,
	'modify_date'         => $m_now_time,
	'adminid'             => 0,
	'register_date'       => $m_now_time,
	'myinfo'              => $userid
	);
	$insert_id = $db->insert("{$tablepre}member_table",dhtmlchars($rows));

	//写入默认收货地址
	$address_row=array(
	'consignee'=>$name,
	'email'=>$email,
	'tel'=>$tel1,
	'mobile'=>$tel2,
	'zipcode'=>$zip,
	'province'=>$province,
	'city'=>$city,
	'address'=>$address1,
	'member_id'=>$insert_id
	);
	$db->insert("{$tablepre}address",dhtmlchars($address_row));

	//注册送积分
	if ($mm_point_member != '0' && $login_id){
		$query = "INSERT INTO `{$tablepre}point_table` SET
                      point_id       = '$login_id',
                      point_add      = '$mm_point_member',
                      point_reason   = '$lang[point_reg_msg]',
                      point_category = '1',
                      modify_id      = '$login_id',
                      modify_ip      = '$m_user_ip',
                      register_date  = '$m_now_time',
                      approval_date  = '$m_now_time'";
		$db->query($query);
	}
	// 注册送预付款
	if ($mm_mony_member != '0' && $login_id){
		$query = "INSERT INTO `{$tablepre}money_table` SET
                      money_id       = '$login_id',
                      money_add      = '$mm_mony_member',
                      money_reason   = '$lang[money_reg_msg]',
                      modify_id      = '$login_id',
                      modify_ip      = '$m_user_ip',
                      money_category = '2',
                      register_date  = '$m_now_time',
                      approval_date  = '$m_now_time' ";
		$db->query($query);
	}

	//发送电子邮件通知
	if ($mm_mail_member == '1') {
	    include_once template('email_reg');
		smtp_mail($email,"$name [$lang[reg_welcome]] ",clean_html('red'));
		unset($mail_content);
	}
	
	// 发送短信
	if ($tel2 != '' && $mm_sms_use == '1' && $mm_sms_member == '1'){
		$sendtel = $mm_sms_useadmin == '1' ? $tel2.';'.$mm_client_phone4 : $tel2;
		sms_send($sendtel,$mm_sms_message1);
	}

	//会员整合插件
	$result = $db->query("SELECT id,class_name,cfg FROM `{$tablepre}passport`");
	while ($port = $db->fetch_array($result)){
		include_once 'include/passport/'. $port['class_name'].'.class.php';
		$rowst = new  $port['class_name'](unserialize($port['cfg']));
		$rowst->post_reg($rows);
	}
	$login_pass = $pass1;
	require_once 'include/passport.inc.php';
	exit;
}

//注册页面
else{
	if (!$setp && $mm_term==1){
		$page        = ShowPage('page_member');//会员协议，可后台添加
		$page_member = $page[conter];
	}
	require_once MVMMALL_ROOT . 'header.php';
	include template('register');
	footer();
}
